home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1994 August / August CD.bin / Shareware / Education / numericalmethods Folder / chap_2 / new2dim.m < prev    next >
Encoding:
Text File  |  1994-06-05  |  943 b   |  34 lines  |  [MATF/MATL]

  1. function [P0,Y0,err,P] = new2dim(F,J,P0,delta,epsilon,max1)
  2. % [P0,F0,err] = new2dim(F,J,P0,delta,epsilon,max1)
  3. % [P0,F0,err,P] = new2dim(F,J,P0,delta,epsilon,max1)
  4. % Newton's point iteration for higher dimensions.
  5. % F is the vector function, input.
  6. % J is the Jacobian matrix for F, input.
  7. % P0 is the starting vector, input.
  8. % delta is the tolerance for P0, input.
  9. % epsilon is the tolerance for Y0, input.
  10. % max1 is the maximum number of iterations, input.
  11. % P0 is the vector solution, output.
  12. % Y0 is the function vector, output.
  13. % err is the error estimate for P0, output.
  14. % P  is the matrix of iterations, output.
  15. P = P0;
  16. Y0 = feval(F,P0);
  17. for k=1:max1,
  18.   dF = feval(J,P0);
  19.   if det(dF) == 0,
  20.     dP = [0 0];
  21.   else
  22.     dP = (dF\Y0)';
  23.   end
  24.   P1 = P0 - dP;
  25.   Y1 = feval(F,P1);
  26.   err = norm(dP);
  27.   relerr = err/(norm(P1)+eps);
  28.   P0 = P1;
  29.   Y0 = Y1;
  30.   P = [P;P1];
  31.   if (err<delta)|(relerr<delta)|(abs(Y1)<epsilon), break, end
  32. end
  33. Y0 = Y0';
  34.